package com.xyy.saas.payment.service.impl;

import com.xyy.saas.payment.dao.mapper.PayFinanceRefundPlanMapper;
import com.xyy.saas.payment.dao.model.PayFinanceRefundPlan;
import com.xyy.saas.payment.dao.model.PayFinanceRefundPlanQueryParam;
import com.xyy.saas.payment.dao.model.PinganLoanDetailQuery;
import com.xyy.saas.payment.dao.model.PinganLoanMyLoanQuery;
import com.xyy.saas.payment.dto.PinganLoanCheckAmountDto;
import com.xyy.saas.payment.dto.PinganLoanMyLoanRecordDto;
import com.xyy.saas.payment.service.PinganLoanFinanceRefundPlanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

@Service
@Slf4j
public class PinganLoanFinanceRefundPlanServiceImpl implements PinganLoanFinanceRefundPlanService {

    @Resource
    private PayFinanceRefundPlanMapper payFinanceRefundPlanMapper;

    @Override
    public Long getTotal(PayFinanceRefundPlanQueryParam planQueryParam) {
        return payFinanceRefundPlanMapper.getTotal(planQueryParam);
    }

    @Override
    public List<PayFinanceRefundPlan> queryByPage(PayFinanceRefundPlanQueryParam param) {
        Integer page = param.getPage();
        param.setOffset(((page == 0 ? 1 : page) - 1) * param.getPageSize());
        return payFinanceRefundPlanMapper.pageListByParam(param);
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return payFinanceRefundPlanMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void batchDelete(List<String> ids) {
        payFinanceRefundPlanMapper.batchDelete(ids);
    }

    @Override
    public int insertSelective(PayFinanceRefundPlan record) {
        return payFinanceRefundPlanMapper.insertSelective(record);
    }

    @Override
    public void batchInsert(List<PayFinanceRefundPlan> list) {
        payFinanceRefundPlanMapper.batchInsert(list);
    }

    @Override
    public PayFinanceRefundPlan selectByPrimaryKey(Long id) {
        return payFinanceRefundPlanMapper.selectByPrimaryKey(id);
    }

    @Override
    public PayFinanceRefundPlan selectByLoanBalanceNo(String loanBalanceNo) {
        return payFinanceRefundPlanMapper.selectByLoanBalanceNo(loanBalanceNo);
    }

    @Override
    public Boolean isExist(String loanBalanceNo) {
        Long id = payFinanceRefundPlanMapper.queryIdByLoanBalanceNo(loanBalanceNo);
        if (id != null) {
            return true;
        }
        return false;
    }

    @Override
    public List<PayFinanceRefundPlan> query(Set<String> loanBalanceNos) {
        return payFinanceRefundPlanMapper.query(loanBalanceNos);
    }

    @Override
    public int updateByPrimaryKeySelective(PayFinanceRefundPlan record) {
        return payFinanceRefundPlanMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int deleteByLoanBalanceNo(String loanBalanceNo) {
        return payFinanceRefundPlanMapper.deleteByLoanBalanceNo(loanBalanceNo);
    }

    @Override
    public List<PayFinanceRefundPlan> pageListByParam(PayFinanceRefundPlanQueryParam planQueryParam) {
        return payFinanceRefundPlanMapper.pageListByParam(planQueryParam);
    }

    @Override
    public int deleteLoan(PayFinanceRefundPlan param) {
        return payFinanceRefundPlanMapper.deleteLoan(param);
    }

    /**
     * 查询剩余应还本金
     */
    @Override
    public PayFinanceRefundPlan curPrincipalAmountBalance(String merchantId) {
        return payFinanceRefundPlanMapper.curPrincipalAmountBalance(merchantId);
    }

    /**
     * 我的平安贷
     */
    @Override
    public List<PinganLoanMyLoanRecordDto> myLoan(PinganLoanMyLoanQuery param) {
        return payFinanceRefundPlanMapper.myLoan(param);
    }

    /**
     * 平安贷明细
     */
    @Override
    public List<PayFinanceRefundPlan> loanDetail(PinganLoanDetailQuery pinganLoanDetailQuery) {
        return payFinanceRefundPlanMapper.loanDetail(pinganLoanDetailQuery);
    }

    /**
     * 平安贷还款计划金额对账，验证平安贷还款计划是否与业务数据金额一致
     */
    @Override
    public List<PinganLoanCheckAmountDto> checkLoanAmount() {
        return payFinanceRefundPlanMapper.checkLoanAmount();
    }

}
